<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the ProjectService class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single ProjectService object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a ProjectServiceMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 *
	 * @package flx_qcubed
	 * @subpackage MetaControls
	 * @property-read ProjectService $ProjectService the actual ProjectService data class being edited
	 * @property QListBox $ProjectIdControl
	 * @property-read QLabel $ProjectIdLabel
	 * @property QListBox $ServiceIdControl
	 * @property-read QLabel $ServiceIdLabel
	 * @property QTextBox $LogUserControl
	 * @property-read QLabel $LogUserLabel
	 * @property QDateTimePicker $LogInsertControl
	 * @property-read QLabel $LogInsertLabel
	 * @property QLabel $LogUpdateControl
	 * @property-read QLabel $LogUpdateLabel
	 * @property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * @property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class ProjectServiceMetaControlGen extends QBaseClass {
		// General Variables
		/**
		 * @var ProjectService objProjectService
		 * @access protected
		 */
		protected $objProjectService;
		/**
		 * @var QForm|QControl objParentObject
		 * @access protected
		 */
		protected $objParentObject;
		/**
		 * @var string strTitleVerb
		 * @access protected
		 */
		protected $strTitleVerb;
		/**
		 * @var boolean blnEditMode
		 * @access protected
		 */
		protected $blnEditMode;

		// Controls that allow the editing of ProjectService's individual data fields
		/**
		 * @var QListBox lstProject
		 * @access protected
		 */
		protected $lstProject;
		/**
		 * @var QListBox lstService
		 * @access protected
		 */
		protected $lstService;
		/**
		 * @var QTextBox txtLogUser
		 * @access protected
		 */
		protected $txtLogUser;
		/**
		 * @var QDateTimePicker calLogInsert
		 * @access protected
		 */
		protected $calLogInsert;
		/**
		 * @var QLabel lblLogUpdate
		 * @access protected
		 */
		protected $lblLogUpdate;

		// Controls that allow the viewing of ProjectService's individual data fields
		/**
		 * @var QLabel lblProjectId
		 * @access protected
		 */
		protected $lblProjectId;
		/**
		 * @var QLabel lblServiceId
		 * @access protected
		 */
		protected $lblServiceId;
		/**
		 * @var QLabel lblLogUser
		 * @access protected
		 */
		protected $lblLogUser;
		/**
		 * @var QLabel lblLogInsert
		 * @access protected
		 */
		protected $lblLogInsert;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * ProjectServiceMetaControl to edit a single ProjectService object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single ProjectService object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ProjectServiceMetaControl
		 * @param ProjectService $objProjectService new or existing ProjectService object
		 */
		 public function __construct($objParentObject, ProjectService $objProjectService) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this ProjectServiceMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked ProjectService object
			$this->objProjectService = $objProjectService;

			// Figure out if we're Editing or Creating New
			if ($this->objProjectService->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to
		 * edit, or if we are also allowed to create a new one, etc.
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ProjectServiceMetaControl
		 * @param integer $intProjectId primary key value
		 * @param integer $intServiceId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing ProjectService object creation - defaults to CreateOrEdit
 		 * @return ProjectServiceMetaControl
		 */
		public static function Create($objParentObject, $intProjectId = null, $intServiceId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intProjectId) && strlen($intServiceId)) {
				$objProjectService = ProjectService::Load($intProjectId, $intServiceId);

				// ProjectService was found -- return it!
				if ($objProjectService)
					return new ProjectServiceMetaControl($objParentObject, $objProjectService);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a ProjectService object with PK arguments: ' . $intProjectId . ', ' . $intServiceId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new ProjectServiceMetaControl($objParentObject, new ProjectService());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ProjectServiceMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing ProjectService object creation - defaults to CreateOrEdit
		 * @return ProjectServiceMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intProjectId = QApplication::PathInfo(0);
			$intServiceId = QApplication::PathInfo(1);
			return ProjectServiceMetaControl::Create($objParentObject, $intProjectId, $intServiceId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ProjectServiceMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing ProjectService object creation - defaults to CreateOrEdit
		 * @return ProjectServiceMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intProjectId = QApplication::QueryString('intProjectId');
			$intServiceId = QApplication::QueryString('intServiceId');
			return ProjectServiceMetaControl::Create($objParentObject, $intProjectId, $intServiceId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QListBox lstProject
		 * @param string $strControlId optional ControlId to use
		 * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself
		 * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query
		 * @return QListBox
		 */
		public function lstProject_Create($strControlId = null, QQCondition $objCondition = null, $objOptionalClauses = null) {
			$this->lstProject = new QListBox($this->objParentObject, $strControlId);
			$this->lstProject->Name = QApplication::Translate('Project');
			$this->lstProject->Required = true;
			if (!$this->blnEditMode)
				$this->lstProject->AddItem(QApplication::Translate('- Select One -'), null);

			// Setup and perform the Query
			if (is_null($objCondition)) $objCondition = QQ::All();
			$objProjectCursor = Project::QueryCursor($objCondition, $objOptionalClauses);

			// Iterate through the Cursor
			while ($objProject = Project::InstantiateCursor($objProjectCursor)) {
				$objListItem = new QListItem($objProject->__toString(), $objProject->Id);
				if (($this->objProjectService->Project) && ($this->objProjectService->Project->Id == $objProject->Id))
					$objListItem->Selected = true;
				$this->lstProject->AddItem($objListItem);
			}

			// Return the QListBox
			return $this->lstProject;
		}

		/**
		 * Create and setup QLabel lblProjectId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblProjectId_Create($strControlId = null) {
			$this->lblProjectId = new QLabel($this->objParentObject, $strControlId);
			$this->lblProjectId->Name = QApplication::Translate('Project');
			$this->lblProjectId->Text = ($this->objProjectService->Project) ? $this->objProjectService->Project->__toString() : null;
			$this->lblProjectId->Required = true;
			return $this->lblProjectId;
		}

		/**
		 * Create and setup QListBox lstService
		 * @param string $strControlId optional ControlId to use
		 * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself
		 * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query
		 * @return QListBox
		 */
		public function lstService_Create($strControlId = null, QQCondition $objCondition = null, $objOptionalClauses = null) {
			$this->lstService = new QListBox($this->objParentObject, $strControlId);
			$this->lstService->Name = QApplication::Translate('Service');
			$this->lstService->Required = true;
			if (!$this->blnEditMode)
				$this->lstService->AddItem(QApplication::Translate('- Select One -'), null);

			// Setup and perform the Query
			if (is_null($objCondition)) $objCondition = QQ::All();
			$objServiceCursor = Service::QueryCursor($objCondition, $objOptionalClauses);

			// Iterate through the Cursor
			while ($objService = Service::InstantiateCursor($objServiceCursor)) {
				$objListItem = new QListItem($objService->__toString(), $objService->Id);
				if (($this->objProjectService->Service) && ($this->objProjectService->Service->Id == $objService->Id))
					$objListItem->Selected = true;
				$this->lstService->AddItem($objListItem);
			}

			// Return the QListBox
			return $this->lstService;
		}

		/**
		 * Create and setup QLabel lblServiceId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblServiceId_Create($strControlId = null) {
			$this->lblServiceId = new QLabel($this->objParentObject, $strControlId);
			$this->lblServiceId->Name = QApplication::Translate('Service');
			$this->lblServiceId->Text = ($this->objProjectService->Service) ? $this->objProjectService->Service->__toString() : null;
			$this->lblServiceId->Required = true;
			return $this->lblServiceId;
		}

		/**
		 * Create and setup QTextBox txtLogUser
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtLogUser_Create($strControlId = null) {
			$this->txtLogUser = new QTextBox($this->objParentObject, $strControlId);
			$this->txtLogUser->Name = QApplication::Translate('Log User');
			$this->txtLogUser->Text = $this->objProjectService->LogUser;
			$this->txtLogUser->MaxLength = ProjectService::LogUserMaxLength;
			return $this->txtLogUser;
		}

		/**
		 * Create and setup QLabel lblLogUser
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblLogUser_Create($strControlId = null) {
			$this->lblLogUser = new QLabel($this->objParentObject, $strControlId);
			$this->lblLogUser->Name = QApplication::Translate('Log User');
			$this->lblLogUser->Text = $this->objProjectService->LogUser;
			return $this->lblLogUser;
		}

		/**
		 * Create and setup QDateTimePicker calLogInsert
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calLogInsert_Create($strControlId = null) {
			$this->calLogInsert = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calLogInsert->Name = QApplication::Translate('Log Insert');
			$this->calLogInsert->DateTime = $this->objProjectService->LogInsert;
			$this->calLogInsert->DateTimePickerType = QDateTimePickerType::DateTime;
			return $this->calLogInsert;
		}

		/**
		 * Create and setup QLabel lblLogInsert
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblLogInsert_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblLogInsert = new QLabel($this->objParentObject, $strControlId);
			$this->lblLogInsert->Name = QApplication::Translate('Log Insert');
			$this->strLogInsertDateTimeFormat = $strDateTimeFormat;
			$this->lblLogInsert->Text = sprintf($this->objProjectService->LogInsert) ? $this->objProjectService->LogInsert->qFormat($this->strLogInsertDateTimeFormat) : null;
			return $this->lblLogInsert;
		}

		protected $strLogInsertDateTimeFormat;


		/**
		 * Create and setup QLabel lblLogUpdate
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblLogUpdate_Create($strControlId = null) {
			$this->lblLogUpdate = new QLabel($this->objParentObject, $strControlId);
			$this->lblLogUpdate->Name = QApplication::Translate('Log Update');
			if ($this->blnEditMode)
				$this->lblLogUpdate->Text = $this->objProjectService->LogUpdate;
			else
				$this->lblLogUpdate->Text = 'N/A';
			return $this->lblLogUpdate;
		}



		/**
		 * Refresh this MetaControl with Data from the local ProjectService object.
		 * @param boolean $blnReload reload ProjectService from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objProjectService->Reload();

			if ($this->lstProject) {
					$this->lstProject->RemoveAllItems();
				if (!$this->blnEditMode)
					$this->lstProject->AddItem(QApplication::Translate('- Select One -'), null);
				$objProjectArray = Project::LoadAll();
				if ($objProjectArray) foreach ($objProjectArray as $objProject) {
					$objListItem = new QListItem($objProject->__toString(), $objProject->Id);
					if (($this->objProjectService->Project) && ($this->objProjectService->Project->Id == $objProject->Id))
						$objListItem->Selected = true;
					$this->lstProject->AddItem($objListItem);
				}
			}
			if ($this->lblProjectId) $this->lblProjectId->Text = ($this->objProjectService->Project) ? $this->objProjectService->Project->__toString() : null;

			if ($this->lstService) {
					$this->lstService->RemoveAllItems();
				if (!$this->blnEditMode)
					$this->lstService->AddItem(QApplication::Translate('- Select One -'), null);
				$objServiceArray = Service::LoadAll();
				if ($objServiceArray) foreach ($objServiceArray as $objService) {
					$objListItem = new QListItem($objService->__toString(), $objService->Id);
					if (($this->objProjectService->Service) && ($this->objProjectService->Service->Id == $objService->Id))
						$objListItem->Selected = true;
					$this->lstService->AddItem($objListItem);
				}
			}
			if ($this->lblServiceId) $this->lblServiceId->Text = ($this->objProjectService->Service) ? $this->objProjectService->Service->__toString() : null;

			if ($this->txtLogUser) $this->txtLogUser->Text = $this->objProjectService->LogUser;
			if ($this->lblLogUser) $this->lblLogUser->Text = $this->objProjectService->LogUser;

			if ($this->calLogInsert) $this->calLogInsert->DateTime = $this->objProjectService->LogInsert;
			if ($this->lblLogInsert) $this->lblLogInsert->Text = sprintf($this->objProjectService->LogInsert) ? $this->objProjectService->LogInsert->qFormat($this->strLogInsertDateTimeFormat) : null;

			if ($this->lblLogUpdate) if ($this->blnEditMode) $this->lblLogUpdate->Text = $this->objProjectService->LogUpdate;

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////





		///////////////////////////////////////////////
		// PUBLIC PROJECTSERVICE OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's ProjectService instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveProjectService() {
			try {
				// Update any fields for controls that have been created
				if ($this->lstProject) $this->objProjectService->ProjectId = $this->lstProject->SelectedValue;
				if ($this->lstService) $this->objProjectService->ServiceId = $this->lstService->SelectedValue;
				if ($this->txtLogUser) $this->objProjectService->LogUser = $this->txtLogUser->Text;
				if ($this->calLogInsert) $this->objProjectService->LogInsert = $this->calLogInsert->DateTime;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the ProjectService object
				$this->objProjectService->Save();

				// Finally, update any ManyToManyReferences (if any)
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's ProjectService instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteProjectService() {
			$this->objProjectService->Delete();
		}



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'ProjectService': return $this->objProjectService;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to ProjectService fields -- will be created dynamically if not yet created
				case 'ProjectIdControl':
					if (!$this->lstProject) return $this->lstProject_Create();
					return $this->lstProject;
				case 'ProjectIdLabel':
					if (!$this->lblProjectId) return $this->lblProjectId_Create();
					return $this->lblProjectId;
				case 'ServiceIdControl':
					if (!$this->lstService) return $this->lstService_Create();
					return $this->lstService;
				case 'ServiceIdLabel':
					if (!$this->lblServiceId) return $this->lblServiceId_Create();
					return $this->lblServiceId;
				case 'LogUserControl':
					if (!$this->txtLogUser) return $this->txtLogUser_Create();
					return $this->txtLogUser;
				case 'LogUserLabel':
					if (!$this->lblLogUser) return $this->lblLogUser_Create();
					return $this->lblLogUser;
				case 'LogInsertControl':
					if (!$this->calLogInsert) return $this->calLogInsert_Create();
					return $this->calLogInsert;
				case 'LogInsertLabel':
					if (!$this->lblLogInsert) return $this->lblLogInsert_Create();
					return $this->lblLogInsert;
				case 'LogUpdateControl':
					if (!$this->lblLogUpdate) return $this->lblLogUpdate_Create();
					return $this->lblLogUpdate;
				case 'LogUpdateLabel':
					if (!$this->lblLogUpdate) return $this->lblLogUpdate_Create();
					return $this->lblLogUpdate;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to ProjectService fields
					case 'ProjectIdControl':
						return ($this->lstProject = QType::Cast($mixValue, 'QControl'));
					case 'ServiceIdControl':
						return ($this->lstService = QType::Cast($mixValue, 'QControl'));
					case 'LogUserControl':
						return ($this->txtLogUser = QType::Cast($mixValue, 'QControl'));
					case 'LogInsertControl':
						return ($this->calLogInsert = QType::Cast($mixValue, 'QControl'));
					case 'LogUpdateControl':
						return ($this->lblLogUpdate = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>